package com.fz.security.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public class JwtUser implements UserDetails {
    @ApiModelProperty(value = "用户主键ID")
    private final String id;
    @ApiModelProperty(value = "用户姓名")
    private final String username;
    @ApiModelProperty(value = "用户登录账号")
    private final String loginId;
    @JsonIgnore
    private final String password;
    @ApiModelProperty(value = "用户授权信息")
    @JsonIgnore
    private final Collection<GrantedAuthority> authorities;









    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }


    public Collection getRoles() {
        return authorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
    }
}
